package com.gc.controller.checkServlet;


import com.gc.service.CheckService;
import com.gc.service.impl.CheckServiceImpl;
import com.gc.util.result.R;
import com.gc.vo.CheckShow;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "checkFind", value = "/checkFind" )
public class checkFind extends HttpServlet {
    CheckService checkService = new CheckServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); //按照 yyyy-MM-dd HH:mm:ss格式化。

        List<CheckShow> checks = checkService.FindAll();
        System.out.println(checks);
        response.getWriter().write(gson.toJson(R.ok().data(checks)));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); //按照 yyyy-MM-dd HH:mm:ss格式化。

        List<CheckShow> checks = checkService.FindAll();
        System.out.println(checks);

        response.getWriter().write(gson.toJson(R.ok().data(checks)));
    }
}
